package daosimp;

import modelo.Alumno;
import modelo.Persona;

import org.hibernate.Query;
import org.hibernate.Transaction;

import util1.HibernateUtil;
import daos.AlumnoDAO;

public class AlumnoDAOIMP implements AlumnoDAO {

	private Transaction tx;

	@Override
	public Alumno obtenerAlumnoxPersona(Persona persona) {
		Alumno alumno = null;
		try {
			tx = HibernateUtil.session.beginTransaction();
			String hql = "FROM Alumno where idPersona ='"
					+ persona.getIdPersona() + "'";
			Query query = HibernateUtil.session.createQuery(hql);
			if (!query.list().isEmpty()) {
				alumno = (Alumno) query.list().get(0);
			}
			tx.commit();
		} catch (Exception e) {
			tx.rollback();
		}
		return alumno;
	}

	@Override
	public void modificarAlumno(Alumno alumno) {
		try {
			tx = HibernateUtil.session.beginTransaction();
			HibernateUtil.session.update(alumno);
			tx.commit();
		} catch (Exception e) {
			tx.rollback();
		}
	}

}
